<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="ctx" th:content="${#httpServletRequest.getContextPath()}" />
    <title>修改密码</title>
    <link rel="stylesheet" th:href="@{/css/admin/base.css}">
    <link rel="stylesheet" th:href="@{/lib/font-awesome/4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/css/admin/app.css}">
</head>

<body>
    <div class="app-page">
        <div class="app-page-header">
            <div class="page-title">修改密码</div>
        </div>
        <div class="app-page-content">
            <div class="app-card">
                <div class="app-card-body">
                    <form class="form">
                        <input type="hidden" name="username" th:value="${username}"/>
                        <div class="form-item row">
                            <div class="label">
                                <label>原密码</label>
                            </div>
                            <div class="body">
                                <input type="password" name="password" data-name="原密码" data-rule="required">
                            </div>
                        </div>
                        <div class="form-item row">
                            <div class="label">
                                <label>新密码</label>
                            </div>
                            <div class="body">
                                <input type="password" name="newPassword" data-name="新密码" data-rule="required">
                            </div>
                        </div>
                        <div class="form-item row">
                            <div class="label">
                                <label>确认密码</label>
                            </div>
                            <div class="body">
                                <input type="password" name="confirmedPassword" data-name="确认密码" data-rule="required">
                            </div>
                        </div>
                        <div class="z-btn-group" style="margin-bottom:0;">
                            <a class="btn-submit z-btn z-primary">更新密码</a>
                            <!--<a href="./list.html" class="layer-close z-btn z-default">返回</a>-->
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script th:src="@{/lib/jquery.min.js}"></script>
    <script th:src="@{/lib/layer-v3.1.1/layer/layer.js}"></script>
    <script th:src="@{/js/popup.js}"></script>
    <script th:src="@{/js/form.js}"></script>
    <script th:src="@{/js/admin/app.js}"></script>
    <script type="text/javascript" th:inline="javascript">
        //获取context path
        var context = $("meta[name='ctx']").attr("content") || '';
        // 保存
        var form = $(".form").form({
            submitSelector: ".form .btn-submit",
            msg: function(msg) {
                popup.tipsTop(msg, 'warning');
            },
            submit: function() {
                var data = {};
                $.each($(".form").serializeArray(), function(index, field) {
                    if (data[field.name]) {
                        data[field.name] += "," + field.value;
                    } else {
                        data[field.name] = field.value;
                    }
                })
                $.ajax({
                    type:"POST",
                    url : context + "/web/updatePassword",
                    data:data,
                    success: function(obj) {
                        var code = obj.code;
                        if (code == 0) {
                            top.location.href = context + "/logout"
                            // window.navigate(context + "/logout");
                        } else {
                            popup.tipsTop(obj.msg, 'warning');
                        }
                    }
                })
            }
        })
    </script>
</body>

</html>